﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:common="clr-namespace:Brjnk.Common;assembly=Common"
                    xmlns:controls="clr-namespace:Brjnk.GpxExplorer.UI.Controls"
                    xmlns:data="clr-namespace:Brjnk.GpxExplorer.Data"
                    xmlns:l="clr-namespace:Brjnk.GpxExplorer.Localization"
                    xmlns:layers="clr-namespace:Brjnk.CoordinateSystem2D.Layers;assembly=CoordinateSystem2D"
                    xmlns:loc="clr-namespace:Brjnk.GpxExplorer.Localization"
                    xmlns:local="clr-namespace:Brjnk.GpxExplorer"
                    xmlns:searching="clr-namespace:Brjnk.GpxExplorer.Workspace.Searching"
                    xmlns:ui="clr-namespace:Brjnk.Common.UI;assembly=Common"
                    xmlns:vm="clr-namespace:Brjnk.GpxExplorer.ViewModel"
                    xmlns:workspace="clr-namespace:Brjnk.GpxExplorer.Workspace">

    <SolidColorBrush x:Key="AreaLabelBackground" Color="#70FFFFFF" />

    <DataTemplate x:Key="AreaWaypointTemplate">
        <!--  Stejné hodnoty CenterX a CenterY musí být nastaveny na AreaWaypointResultTemplate!!!  -->
        <StackPanel ui:Canvas.CenterX="50%" ui:Canvas.CenterY="_5">
            <StackPanel.Resources>
                <Style TargetType="TextBlock">
                    <Style.Triggers>
                        <Trigger Property="Text" Value="">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="Text" Value="{x:Null}">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </StackPanel.Resources>
            <StackPanel Background="{StaticResource AreaLabelBackground}">
                <ContentControl Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowName, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                    <TextBlock FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize,
                                                  RelativeSource={RelativeSource Mode=Self}}"
                               FontWeight="Bold"
                               Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color,
                                                    RelativeSource={RelativeSource Mode=Self},
                                                    Converter={StaticResource ColorToBrushConverter}}"
                               Text="{Binding Source.Name}" />
                </ContentControl>
                <ContentControl Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowComment, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                    <TextBlock FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize,
                                                  RelativeSource={RelativeSource Mode=Self}}"
                               Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color,
                                                    RelativeSource={RelativeSource Mode=Self},
                                                    Converter={StaticResource ColorToBrushConverter}}"
                               Text="{Binding Source.Comment}" />
                </ContentControl>
                <ContentControl Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowDescription, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                    <TextBlock FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize,
                                                  RelativeSource={RelativeSource Mode=Self}}"
                               Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color,
                                                    RelativeSource={RelativeSource Mode=Self},
                                                    Converter={StaticResource ColorToBrushConverter}}"
                               Text="{Binding Source.Description}" />
                </ContentControl>
                <ContentControl Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowElevation, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                    <TextBlock FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize,
                                                  RelativeSource={RelativeSource Mode=Self}}"
                               Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color,
                                                    RelativeSource={RelativeSource Mode=Self},
                                                    Converter={StaticResource ColorToBrushConverter}}"
                               Text="{Binding Source.Elevation,
                                              Converter={StaticResource ElevationConverter}}" />
                </ContentControl>
                <ContentControl Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowTime, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                    <TextBlock FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize,
                                                  RelativeSource={RelativeSource Mode=Self}}"
                               Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color,
                                                    RelativeSource={RelativeSource Mode=Self},
                                                    Converter={StaticResource ColorToBrushConverter}}"
                               Text="{Binding Source.Time,
                                              Converter={StaticResource NullableConverter}}" />
                </ContentControl>
                <ContentControl Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowGCName, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                    <TextBlock FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize,
                                                  RelativeSource={RelativeSource Mode=Self}}"
                               Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color,
                                                    RelativeSource={RelativeSource Mode=Self},
                                                    Converter={StaticResource ColorToBrushConverter}}"
                               Text="{Binding Source.Geocache.Name}" />
                </ContentControl>
                <ContentControl Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowGCType, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                    <TextBlock FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize,
                                                  RelativeSource={RelativeSource Mode=Self}}"
                               Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color,
                                                    RelativeSource={RelativeSource Mode=Self},
                                                    Converter={StaticResource ColorToBrushConverter}}"
                               Text="{Binding Source.Geocache.Type}" />
                </ContentControl>
                <!--Terrain, Difficulty, Size-->
                <StackPanel Orientation="Horizontal">
                    <ContentControl Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowGCTDSize, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                        <TextBlock Margin="0 0 5 0" FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize,
                                                  RelativeSource={RelativeSource Mode=Self}}"
                               Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color,
                                                    RelativeSource={RelativeSource Mode=Self},
                                                    Converter={StaticResource ColorToBrushConverter}}"
                               Text="{Binding Source.Geocache.Difficulty}" />
                    </ContentControl>
                    <ContentControl Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowGCTDSize, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                        <TextBlock Margin="0 0 5 0" FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize,
                                                  RelativeSource={RelativeSource Mode=Self}}"
                               Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color,
                                                    RelativeSource={RelativeSource Mode=Self},
                                                    Converter={StaticResource ColorToBrushConverter}}"
                               Text="{Binding Source.Geocache.Terrain}" />
                    </ContentControl>
                    <ContentControl Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowGCTDSize, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                        <TextBlock Margin="0 0 5 0" FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize,
                                                  RelativeSource={RelativeSource Mode=Self}}"
                               Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color,
                                                    RelativeSource={RelativeSource Mode=Self},
                                                    Converter={StaticResource ColorToBrushConverter}}"
                               Text="{Binding Source.Geocache.Size}" />
                    </ContentControl>
                </StackPanel>
            </StackPanel>
            <Ellipse Width="10"
                     Height="10"
                     Stroke="{Binding Path=(layers:PointsLayer.CustomStyle).PinColor,
                                      RelativeSource={RelativeSource Mode=Self},
                                      Converter={StaticResource ColorToBrushConverter}}"
                     StrokeThickness="2">
                <Ellipse.Style>
                    <Style TargetType="Ellipse">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsSelected}" Value="True">
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard Name="bsb">
                                        <Storyboard>
                                            <DoubleAnimation AutoReverse="true"
                                                             From="2"
                                                             RepeatBehavior="Forever"
                                                             Storyboard.TargetProperty="StrokeThickness"
                                                             To="5" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </DataTrigger.EnterActions>
                                <DataTrigger.ExitActions>
                                    <StopStoryboard BeginStoryboardName="bsb" />
                                </DataTrigger.ExitActions>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Ellipse.Style>
            </Ellipse>
        </StackPanel>
    </DataTemplate>

    <DataTemplate x:Key="AreaWaypointResultTemplate">
        <ContentControl Content="{Binding SearchedItem}"
                        ContentTemplate="{StaticResource AreaWaypointTemplate}"
                        ui:Canvas.CenterX="50%"
                        ui:Canvas.CenterY="_5" />
    </DataTemplate>

    <DataTemplate x:Key="AreaSearchRequestTemplate">
        <StackPanel ui:Canvas.CenterX="50%" ui:Canvas.CenterY="_5">
            <StackPanel.Resources>
                <Style TargetType="TextBlock">
                    <Style.Triggers>
                        <Trigger Property="Text" Value="">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="Text" Value="{x:Null}">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </StackPanel.Resources>
            <TextBlock Background="{StaticResource AreaLabelBackground}"
                       FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize,
                                          RelativeSource={RelativeSource Mode=Self}}"
                       FontWeight="Bold"
                       Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color,
                                            RelativeSource={RelativeSource Mode=Self},
                                            Converter={StaticResource ColorToBrushConverter}}"
                       Text="{Binding StringRepresentation}"
                       Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowDescription,
                                            Converter={StaticResource BooleanToVisibilityConverter},
                                            RelativeSource={RelativeSource Mode=Self}}" />

            <!--
                Margin doplní mezeru pod elipsou, aby Cenvas.CenterY mohl být 5.
                CenterY musí být stejný jako AreaWaypointTemplate, protože jsou obě šablony použity v AreaSearchResultTemplate
            -->

            <Ellipse Width="5"
                     Height="5"
                     Margin="0 0 0 2.5"
                     Fill="{Binding Color1,
                                    Converter={StaticResource ColorToBrushConverter}}"
                     Stroke="{Binding Color2,
                                      Converter={StaticResource ColorToBrushConverter}}"
                     StrokeThickness="1" />
        </StackPanel>
    </DataTemplate>

    <DataTemplate x:Key="AreaPushpinTemplate">
        <Grid  ui:Canvas.CenterX="50%" ui:Canvas.CenterY="_5">
            <StackPanel Margin="23 0 0 5">
                <TextBlock Background="{StaticResource AreaLabelBackground}" Text="{Binding StringRepresentation}" />
                <Image Height="48" Width="23" Source="/Resources/Icons/Pushpin.png" />
            </StackPanel>
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="AreaSearchResultTemplate">
        <StackPanel ui:Canvas.CenterX="50%" ui:Canvas.CenterY="_5">
            <ContentControl Content="{Binding SearchedItem}">
                <ContentControl.ContentTemplateSelector>
                    <common:GenericTemplateSelector>
                        <common:TemplateDefinition ObjectType="{x:Type searching:Pushpin}" Template="{StaticResource AreaPushpinTemplate}" />
                        <common:TemplateDefinition Negate="true" Template="{StaticResource AreaSearchRequestTemplate}" />
                    </common:GenericTemplateSelector>
                </ContentControl.ContentTemplateSelector>
            </ContentControl>
        </StackPanel>
    </DataTemplate>

    <DataTemplate x:Key="AreaRoutePointTemplate">
        <StackPanel ui:Canvas.CenterX="50%" ui:Canvas.CenterY="_2.5">
            <StackPanel Background="{StaticResource AreaLabelBackground}">
                <StackPanel.Resources>
                    <Style TargetType="TextBlock">
                        <Style.Triggers>
                            <Trigger Property="Text" Value="">
                                <Setter Property="Visibility" Value="Collapsed" />
                            </Trigger>
                            <Trigger Property="Text" Value="{x:Null}">
                                <Setter Property="Visibility" Value="Collapsed" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </StackPanel.Resources>
                <ContentControl FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize, RelativeSource={RelativeSource Mode=Self}}" Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowNumber, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                    <TextBlock FontWeight="Bold"
                               Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color,
                                                    RelativeSource={RelativeSource Mode=Self},
                                                    Converter={StaticResource ColorToBrushConverter}}"
                               Text="{Binding Number}" />
                </ContentControl>
                <ContentControl FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize, RelativeSource={RelativeSource Mode=Self}}" Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowDistance, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                    <TextBlock Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource ColorToBrushConverter}}" Text="{Binding Distance}" />
                </ContentControl>
            </StackPanel>
            <Ellipse Width="5"
                     Height="5"
                     Stroke="{Binding Path=(layers:PointsLayer.CustomStyle).PinColor,
                                      RelativeSource={RelativeSource Mode=Self},
                                      Converter={StaticResource ColorToBrushConverter}}"
                     StrokeThickness="2" />
        </StackPanel>
    </DataTemplate>

    <DataTemplate x:Key="AreaTrackPointTemplate">
        <StackPanel ui:Canvas.CenterX="50%" ui:Canvas.CenterY="_2.5">
            <StackPanel.Resources>
                <Style TargetType="TextBlock">
                    <Style.Triggers>
                        <Trigger Property="Text" Value="">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="Text" Value="{x:Null}">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </StackPanel.Resources>
            <StackPanel Background="{StaticResource AreaLabelBackground}">
                <ContentControl FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize, RelativeSource={RelativeSource Mode=Self}}" Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowNumber, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                    <TextBlock FontWeight="Bold"
                               Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color,
                                                    RelativeSource={RelativeSource Mode=Self},
                                                    Converter={StaticResource ColorToBrushConverter}}"
                               Text="{Binding Number}" />
                </ContentControl>
                <ContentControl FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize, RelativeSource={RelativeSource Mode=Self}}" Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowDistance, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                    <TextBlock Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource ColorToBrushConverter}}" Text="{Binding Distance}" />
                </ContentControl>
                <ContentControl FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize, RelativeSource={RelativeSource Mode=Self}}" Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowElevation, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                    <TextBlock Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource ColorToBrushConverter}}" Text="{Binding Elevation, Converter={StaticResource TrackPointElevationConverter}}" />
                </ContentControl>
                <ContentControl FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize, RelativeSource={RelativeSource Mode=Self}}" Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowDateTime, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                    <TextBlock Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource ColorToBrushConverter}}" Text="{Binding Time, Converter={StaticResource TrackPointAttributeValueConverter}}" />
                </ContentControl>
                <ContentControl FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize, RelativeSource={RelativeSource Mode=Self}}" Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowTime, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                    <TextBlock Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource ColorToBrushConverter}}" Text="{Binding Time, Converter={StaticResource TrackPointDateTimeToTimeConverter}}" />
                </ContentControl>
                <ContentControl FontSize="{Binding Path=(layers:PointsLayer.CustomStyle).FontSize, RelativeSource={RelativeSource Mode=Self}}" Visibility="{Binding Path=(layers:PointsLayer.CustomStyle).ShowDuration, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}">
                    <TextBlock Foreground="{Binding Path=(layers:PointsLayer.CustomStyle).Color, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource ColorToBrushConverter}}" Text="{Binding Duration, Converter={StaticResource TrackPointAttributeValueConverter}}" />
                </ContentControl>
            </StackPanel>
            <Ellipse Width="5"
                     Height="5"
                     Stroke="{Binding Path=(layers:PointsLayer.CustomStyle).PinColor,
                                      RelativeSource={RelativeSource Mode=Self},
                                      Converter={StaticResource ColorToBrushConverter}}"
                     StrokeThickness="2" />
        </StackPanel>
    </DataTemplate>
</ResourceDictionary>